<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <!-- react容器 -->
    <div id="test"></div>

    <!-- 引入react核心库 -->
    <script src="../lib/react.js"></script>
    <!-- 引入react-dom -->
    <script src="../lib/react-dom.js"></script>
    <!-- 引入babel -->
    <script src="../lib/babel.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/prop-types/15.7.2/prop-types.js"></script>
    <script type="text/babel">
      //1 创建虚拟DOM
      class Person extends React.Component {
        constructor(props){
          console.log(props)
          super(props)
        }
        //对标签属性，进行必要性设置
        static propTypes = {
          name: PropTypes.string.isRequired,
          sex: PropTypes.string,
          age: PropTypes.number,
        };
        //指定默认标签属性值
        static defaultProps = {
          sex: "bunanbunv",
        };
        render() {
          return (
            <div>
              {this.state.data.map((item, index) => {
                return (
                  <ul key={index}>
                    <li>姓名: {item.name}</li>
                    <li>性别: {item.sex}</li>
                    <li>年龄: {item.year + 1}</li>
                  </ul>
                );
              })}
            </div>
          );
        }
        state = {
          data: [
            { name: "Sam", sex: 0, year: 12 },
            { name: "Tom", sex: 1, year: 16 },
          ],
        };
      }

      const p = { name: "wangfen", age: 12, sex: 12 };
      //   const p2 = { ...p };
      //   p.year = 124;
      //   console.log(p2);
      ReactDOM.render(<Person {...p} />, document.getElementById("test"));
    </script>
  </body>
</html>
